/*
 * Copyright (c) 2009 Johnny Mast
 * 
 * Permission is hereby granted, free of charge, to any person
 * obtaining a copy of this software and associated documentation
 * files (the "Software"), to deal in the Software without
 * restriction, including without limitation the rights to use,
 * copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following
 * conditions:
 
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
 */

#import "GameScene.h"

@class TileSet;
@class Layer;
@class HieroBitmapFont;

typedef struct _xfMapSpriteLocation {
	int row;
	int col;
} XFMapSpriteLocation;

@interface TileMap : NSObject
{
@private
	NSMutableDictionary* _mapProperties;
	NSMutableDictionary* _tileSetProperties;
	NSMutableDictionary* _cachedTiles;
	NSString* _mapName;
	NSInteger _mapHeight;
	NSInteger _mapWidth;
	NSInteger _tileWidth;
	NSInteger _tileHeight;
	NSInteger _currentLayerID;
	NSInteger _currentTileSetID;
	NSInteger _tileX;
	NSInteger _tileY;
	SpriteSheet* _ss; // NOTE
	
	
	NSMutableArray *_tileSets;
	NSMutableArray *_layers;
	
	HieroBitmapFont* _font;
	TileSet* _currentTileSet;
}
@property(nonatomic, readonly) NSMutableDictionary* mapProperties;
@property(nonatomic, readonly) NSMutableDictionary* tileSetProperties;
@property(nonatomic, readonly) NSMutableDictionary* cachedTiles;
@property(nonatomic, readonly) NSMutableArray* layers;
@property(nonatomic, readonly) NSString* mapName;
@property(nonatomic, readonly) TileSet* currentTileSet; // note
@property(nonatomic, readonly) NSMutableArray* tileSets;
@property(nonatomic, retain)   HieroBitmapFont* font;

@property(readonly) NSInteger mapWidth;

@property(readonly) NSInteger mapHeight;
@property(readonly) NSInteger tileWidth;
@property(readonly) NSInteger tileHeight;
@property(readonly) NSInteger currentLayerID;
@property(readonly) NSInteger currentTileSetID;
@property(readonly) NSInteger tileX;
@property(readonly) NSInteger tileY;

- (id)initWithTiledFile:(NSString*)mapname fileExtension:(NSString*)aFileExtension;

-(void)renderAtPoint:(CGPoint)point mapX:(NSInteger)MapX mapY:(NSInteger)MapY tilesInWidth:(NSInteger)tilesInWidth tilesInHeight:(NSInteger)tilesInHeight layer:(NSInteger)layerID;
-(void)renderGrid:(CGPoint)point withFont:(NSString*)fontname mapX:(NSInteger)mapX mapY:(NSInteger)mapY tilesInWidth:(NSInteger)tilesInWidth tilesInHeight:(NSInteger)tilesInHeight;
- (NSString*)getTilePropertyForGlobalTileID:(int)aGlobalTileID key:(NSString*)aKey defaultValue:(NSString*)aDefaultValue;
- (NSString*)getTilePropertyForGlobalTileID:(int)aGlobalTileID key:(NSString*)aKey defaultValue:(NSString*)aDefaultValue;
@end
